using System.Data;
using Microsoft.ApplicationBlocks.Data;
using NCS.Library.Utilities;
using NCS.Module.FeedBack.Library.Components;

namespace NCS.Module.FeedBack.Library.Providers
{
	public class SqlDataProvider : DataProvider
	{
		private string _strConn;
		public string ConnectionString
		{
			get { return this._strConn; }
			set { this._strConn = value; }
		}
		public SqlDataProvider(string strConn)
		{
			this.ConnectionString = strConn;
		}
		public override DataTable GetFeedBacks(int status)
		{
			DataSet ds = SqlHelper.ExecuteDataset(this.ConnectionString, "FeedBacks_GetAll", status);
			if (ds != null && ds.Tables.Count > 0) return ds.Tables[0];
			return null;
		}
		public override FeedBackInfo GetFeedBack(int fbId)
		{
			IDataReader dr = SqlHelper.ExecuteReader(this.ConnectionString, "FeedBacks_GetInfo", fbId);
			FeedBackInfo fbInfo = (FeedBackInfo) ObjectHelper.CreateObject(typeof (FeedBackInfo), dr);
			return fbInfo;
		}
		public override int AddFeedBack(FeedBackInfo fb)
		{
            object obj = SqlHelper.ExecuteScalar(this.ConnectionString, "FeedBacks_Insert", fb.FullName, fb.Email, fb.Tel, fb.Address, fb.Subject, fb.Content, fb.Status);
            return obj != null ? (int)obj : 0;
		}
		public override void UpdateFeedBack(FeedBackInfo fb)
		{
			SqlHelper.ExecuteNonQuery(this.ConnectionString, "FeedBacks_Update", fb.FeedBackID, fb.FullName, fb.Email, fb.Tel, fb.Address, fb.Subject, fb.Content, fb.Status);
		}
		public override void DeleteFeedBack(FeedBackInfo fb)
		{
			SqlHelper.ExecuteNonQuery(this.ConnectionString, "FeedBacks_Delete", fb.FeedBackID);
		}
		public override void DeleteFeedBack(int fbId)
		{
			SqlHelper.ExecuteNonQuery(this.ConnectionString, "FeedBacks_Delete", fbId);
		}
		public override void SetStatus(int fbId, int status)
		{
			SqlHelper.ExecuteNonQuery(this.ConnectionString, "FeedBacks_SetStatus", fbId, status);
		}
	}
}
